use crate::audio_manager;
use tauri::command;

/// 播放错误提示音的Tauri命令
#[command]
pub fn play_error_sound() -> Result<String, String> {
    audio_manager::play_error_notification();
    Ok("Error sound played successfully".to_string())
}

/// 播放指定音频文件的Tauri命令
#[command]
pub fn play_audio_file(file_path: String) -> Result<String, String> {
    match audio_manager::play_audio_file(&file_path) {
        Ok(_) => Ok(format!("Audio file {} played successfully", file_path)),
        Err(e) => Err(format!("Failed to play audio file {}: {}", file_path, e)),
    }
}

/// 设置音频音量的Tauri命令
#[command]
pub fn set_audio_volume(volume: f32) -> Result<String, String> {
    if volume < 0.0 || volume > 1.0 {
        return Err("Volume must be between 0.0 and 1.0".to_string());
    }
    
    audio_manager::set_global_volume(volume);
    Ok(format!("Volume set to {}", volume))
}

/// 获取可用音频文件列表的Tauri命令
#[command]
pub fn get_available_audio_files() -> Result<Vec<String>, String> {
    use std::path::Path;
    
    let audio_files = vec![
        "public/video/placeOrder.wav".to_string(),
        "public/video/sucess.wav".to_string(),
        "public/video/longOnce.wav".to_string(),
        "public/video/fiveTimes.wav".to_string(),
        "public/video/cancelOrder.wav".to_string(),
    ];
    
    let mut available_files = Vec::new();
    
    for file in audio_files {
        if Path::new(&file).exists() {
            available_files.push(file);
        }
    }
    
    Ok(available_files)
}
